<?php

$requete=requete("SELECT * FROM `cron`");
while ($result=mysql_fetch_array($requete))
	{
	$id_cron=$result['id'];
	$lien_cron=$result['lien'];
	$duree_cron=$result['duree'];
	$last_cron=$result['last'];
	if ($last_cron=="0000-00-00 00:00:00")
		{
		$requete1=requete("UPDATE `cron` SET last=NOW() WHERE id='".$id_cron."'");	
		}
	else
		{
		// date : YYYY-MM-DD HH:II:SS
		//echo date("Y m d H i s");
		//echo substr($last_cron,11,2)." ".substr($last_cron,14,2)." ".substr($last_cron,17,2)." ".substr($last_cron,5,2)." ".substr($last_cron,8,2)." ".substr($last_cron,0,4);
		$d=mktime(substr($last_cron,11,2),substr($last_cron,14,2),substr($last_cron,17,2),substr($last_cron,5,2),substr($last_cron,8,2),substr($last_cron,0,4));	
		$d=$d+$duree_cron;			
		$retour=getdate($d);
			
		if (strlen($retour["mon"])==1)
			{
			$retour["mon"]="0".$retour["mon"];
			}
			
		if (strlen($retour["mday"])==1)
			{
			$retour["mday"]="0".$retour["mday"];
			}
			
		if (strlen($retour['hours'])==1)
			{
			$retour["hours"]="0".$retour["hours"];
			}
			
		if (strlen($retour['minutes'])==1)
			{
			$retour["minutes"]="0".$retour["minutes"];	
			}
		
		if (strlen($retour['seconds'])==1)
			{
			$retour["seconds"]="0".$retour["seconds"];
			}
			
			
		$date=$retour["year"]."-".$retour["mon"]."-".$retour["mday"]." ".$retour['hours'].":".$retour['minutes'].":".$retour['seconds'];
		
		
		
		$requete2=requete("SELECT id FROM `cron` WHERE NOW()>'".$date."' AND id='".$id_cron."'");
		$nb=mysql_num_rows($requete2);
		if ($nb==1)
			{
			// execute la tache programmée
			include ($lien_cron);
			$requete3=requete("UPDATE `cron` SET last=NOW() WHERE id='".$id_cron."'");				
			}
	
		}
	
	
	}



//include ('modules/email/email.monitor.cron.php');



?>